home *** CD-ROM | disk | FTP | other *** search
- /*
- FILE: sinegen.c
- PROJECT: Ford grant DSP
- AUTHOR: Ben Denckla
- COMMENT: generates a sine wave of user-specified frequency
- LINKAGE: needs sintab.c
- */
-
- #include "aiff.h"
- #include "sintab.h"
-
- #include <stdio.h>
- #include <math.h> // must come before SANE #include to have precedence
- #include <SANE.h>
-
- #define GETNUM( prompt, fmtstr, x ) { \
- int e; \
- do { \
- printf( prompt ); \
- e = !scanf( fmtstr, &x ) || x < 0; \
- fflush( stdin ); \
- if ( e ) puts( "Try again: input was bad." ); \
- } while ( e ); \
- }
-
- int take_input = 0, make_output = 1;
-
- static short harm;
-
- // asks user for frequency & length of file
- DEFFUNC( void getusrdat( void ) ) {
- GETNUM( "number of samples: ", "%ld", ba.com.fram )
- GETNUM( "sampling rate: ", "%lf", ph.rate )
- }
-
- // sets AIFF header info (all else is default)
- DEFFUNC( void set_vals( void ) ) {
- ba.com.chan = 1;
- // ba.com.fram already set in getusrdat()
- ba.com.wdsi = 16;
- x96tox80( &(ph.rate), &(ba.com.rate) );// convert float formats (1)
- ba.frmhd.si += 2*ba.com.fram; // see aiff.c for initial sizes
- ba.sndhd.si += 2*ba.com.fram; // " " " "
-
- ph.framsiz = 2;
- }
- // 1. rate already set in getusrdat()
-
-
- void init_process( void ) {
- get_sintab(); // get a 1st-quadrant sine wave table
- getusrdat();
- harm = getusrharm();
- set_vals();
- }
-
- void term_process( void ) {
- // no termination needed
- }
-
- void process_samdat( long buflen ) {
- long i;
- register short *td, *endd, tphase, tharm;
- static short phase = 0;
-
- td = d;
- tphase = phase;
- tharm = harm;
- endd = &td[buflen];
-
- do {
- *td++ = sin_tab( tphase &= TABMASK );
- tphase += tharm;
- } while ( td < endd );
-
- phase = tphase;
- }
-